package com.gisuni.sddc.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DateUtil;
/**
 * excel操作类
 *
 * @author zouxiaoming
 */

@SuppressWarnings("deprecation")
public class ExcelOperation {
	@SuppressWarnings("rawtypes")
	public void export(String title,String[] rowName,String[] columntop,List<Map>  dataList,HttpServletResponse response) throws Exception{  
        try{  
            HSSFWorkbook workbook = new HSSFWorkbook();                    
            HSSFSheet sheet = workbook.createSheet(title);                  
            HSSFRow rowm = sheet.createRow(0);  
            HSSFCell cellTiltle = rowm.createCell(0);  
            HSSFCellStyle columnTopStyle = this.getColumnTopStyle(workbook);
            HSSFCellStyle style = this.getStyle(workbook);                 
            sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, (rowName.length-1)));    
            cellTiltle.setCellStyle(columnTopStyle);  
            cellTiltle.setCellValue(title);  
            int columnNum = rowName.length;  
            
            HSSFRow rowRowName = sheet.createRow(2);                
            for(int n=0;n<columnNum;n++){  
                HSSFCell  cellRowName = rowRowName.createCell(n);              
                cellRowName.setCellType(HSSFCell.CELL_TYPE_STRING);             
                HSSFRichTextString text = new HSSFRichTextString(rowName[n]);  
                cellRowName.setCellValue(text);                                 
                cellRowName.setCellStyle(columnTopStyle);                       
            }  
             
            for(int i=0;i<dataList.size();i++){  
                Map obj = dataList.get(i);
                HSSFRow row = sheet.createRow(i+3);
                for(int j=0; j<columntop.length; j++){  
                    HSSFCell  cell = null;  
                    if(j == 0){  
                        cell = row.createCell(j,HSSFCell.CELL_TYPE_NUMERIC);  
                        cell.setCellValue(i+1);   
                    }else{  
                        cell = row.createCell(j,HSSFCell.CELL_TYPE_STRING);  
                        if(obj.get(columntop[j]) != null){  
                            cell.setCellValue(obj.get(columntop[j]).toString());                    
                        } 
                        else{
                        	 cell.setCellValue("");          
                        }
                    }  
                    cell.setCellStyle(style);                                  
                }  
            }  
            //让列宽随着导出的列长自动适应  
            for (int colNum = 0; colNum < columnNum; colNum++) {  
                int columnWidth = sheet.getColumnWidth(colNum) / 256;  
                for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) {  
                    HSSFRow currentRow;  
                    if (sheet.getRow(rowNum) == null) {  
                        currentRow = sheet.createRow(rowNum);  
                    } else {  
                        currentRow = sheet.getRow(rowNum);  
                    }  
                    if (currentRow.getCell(colNum) != null) {  
                        HSSFCell currentCell = currentRow.getCell(colNum);  
                        if (currentCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {  
                            int length = currentCell.getStringCellValue().getBytes().length;  
                            if (columnWidth < length) {  
                                columnWidth = length;  
                            }  
                        }  
                    }  
                }  
                if(colNum == 0){  
                    sheet.setColumnWidth(colNum, (columnWidth-2) * 256);  
                }else{  
                    sheet.setColumnWidth(colNum, (columnWidth+4) * 256);  
                }  
            }  
            if(workbook !=null){  
                try  
                {  
                    String fileName = title + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";  
                    fileName=new String(fileName.getBytes("gb2312"),"iso8859-1");
                    String headStr = "attachment; filename=\"" + fileName + "\"";  
                    response.setContentType("APPLICATION/OCTET-STREAM");  
                    response.setHeader("Content-Disposition", headStr);  
                    OutputStream out = response.getOutputStream();  
                    workbook.write(out); 
                    out.close();
                    out.flush();
                }  
                catch (IOException e)  
                {  
                    e.printStackTrace();  
                }  
            }  
  
        }catch(Exception e){  
            e.printStackTrace();  
        }  
          
    } 
	
	 /**
	  * 专题数据统计导出Excel【Title】
	  * @param title
	  * @param rowName
	  * @param columntop
	  * @param dataList
	  * @param response
	  * @throws Exception
	  */
	
	@SuppressWarnings("rawtypes")
	public void exportSpecil(String title,String[] rowName,String[] columntop,List<Map>  dataList,HttpServletResponse response) throws Exception{  
        try{  
            HSSFWorkbook workbook = new HSSFWorkbook();                    
            HSSFSheet sheet = workbook.createSheet(title);                  
            HSSFRow rowm = sheet.createRow(0);  
            HSSFCell cellTiltle = rowm.createCell(0);  
            HSSFCellStyle columnTopStyle = this.getColumnTopStyle(workbook);
            HSSFCellStyle style = this.getStyle(workbook);                 
            sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, (rowName.length-1)));    
            cellTiltle.setCellStyle(columnTopStyle);  
            cellTiltle.setCellValue(title);  
            int columnNum = rowName.length;  
            
            HSSFRow rowRowName = sheet.createRow(2);                
            for(int n=0;n<columnNum;n++){  
                HSSFCell  cellRowName = rowRowName.createCell(n);              
                cellRowName.setCellType(HSSFCell.CELL_TYPE_STRING);             
                HSSFRichTextString text = new HSSFRichTextString(rowName[n]);  
                cellRowName.setCellValue(text);                                 
                cellRowName.setCellStyle(columnTopStyle);    
            }  
            
            HSSFRow rowRowName1 =sheet.createRow(3); 
            HSSFCell  cellRowName = rowRowName1.createCell(2);              
            cellRowName.setCellType(HSSFCell.CELL_TYPE_STRING);             
            cellRowName.setCellValue("宗数");                                 
            cellRowName.setCellStyle(columnTopStyle);   
            
            
            HSSFCell  cellRowName2 = rowRowName1.createCell(3);              
            cellRowName2.setCellType(HSSFCell.CELL_TYPE_STRING);             
            cellRowName2.setCellValue("面积");                                 
            cellRowName2.setCellStyle(columnTopStyle); 
            
            
            HSSFCell  cellRowName3 = rowRowName1.createCell(4);              
            cellRowName3.setCellType(HSSFCell.CELL_TYPE_STRING);             
            cellRowName3.setCellValue("宗数");                                 
            cellRowName3.setCellStyle(columnTopStyle); 
            
            
            HSSFCell  cellRowName4 = rowRowName1.createCell(5);              
            cellRowName4.setCellType(HSSFCell.CELL_TYPE_STRING);             
            cellRowName4.setCellValue("面积");                                 
            cellRowName4.setCellStyle(columnTopStyle); 
 
            
            // 四个参数分别是：起始列，起始行，结束列 ,结束行，
//            sheet.addMergedRegion(new CellRangeAddress(2, 3, 4, 4));
            // 四个参数分别是：起始行，起始列，结束行，结束列 
            sheet.addMergedRegion(new Region(2, (short) (0), 3,(short) (0)));    
            sheet.addMergedRegion(new Region(2, (short) (1), 3,(short) (1))); 
            sheet.addMergedRegion(new Region(2, (short) (2), 2,(short) (3))); 
            sheet.addMergedRegion(new Region(2, (short) (4), 2,(short) (5))); 
            for(int i=0;i<dataList.size();i++){  
                Map obj = dataList.get(i);
                HSSFRow row = sheet.createRow(i+4);
                for(int j=0; j<columntop.length; j++){  
                    HSSFCell  cell = null;  
                    if(j == 0){  
                        cell = row.createCell(j,HSSFCell.CELL_TYPE_NUMERIC);  
                        cell.setCellValue(i+1);   
                    }else{  
                        cell = row.createCell(j,HSSFCell.CELL_TYPE_STRING);  
                        if(obj.get(columntop[j]) != null){  
                            cell.setCellValue(obj.get(columntop[j]).toString());                    
                        } 
                        else{
                        	 cell.setCellValue("");          
                        }
                    }  
                    cell.setCellStyle(style);                                  
                }  
            }  
            //让列宽随着导出的列长自动适应  
            for (int colNum = 0; colNum < columnNum; colNum++) {  
                int columnWidth = sheet.getColumnWidth(colNum) / 256;  
                for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) {  
                    HSSFRow currentRow;  
                    if (sheet.getRow(rowNum) == null) {  
                        currentRow = sheet.createRow(rowNum);  
                    } else {  
                        currentRow = sheet.getRow(rowNum);  
                    }  
                    if (currentRow.getCell(colNum) != null) {  
                        HSSFCell currentCell = currentRow.getCell(colNum);  
                        if (currentCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {  
                            int length = currentCell.getStringCellValue().getBytes().length;  
                            if (columnWidth < length) {  
                                columnWidth = length;  
                            }  
                        }  
                    }  
                }  
                if(colNum == 0){  
                    sheet.setColumnWidth(colNum, (columnWidth-2) * 256);  
                }else{  
                    sheet.setColumnWidth(colNum, (columnWidth+4) * 256);  
                }  
            }  
            if(workbook !=null){  
                try  
                {  
                    String fileName = title + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";  
                    fileName=new String(fileName.getBytes("gb2312"),"iso8859-1");
                    response.setCharacterEncoding("UTF-8");
                    String headStr = "attachment; filename=\"" + fileName + "\"";  
                    response.setContentType("APPLICATION/OCTET-STREAM");  
                    response.setHeader("Content-Disposition", headStr);  
                    OutputStream out = response.getOutputStream();  
                    workbook.write(out); 
                    out.close();
                    out.flush();
                }  
                catch (IOException e)  
                {  
                    e.printStackTrace();  
                }  
            }  
  
        }catch(Exception e){  
            e.printStackTrace();  
        }  
          
    } 
	
	
	 /*  
     * 列头单元格样式 
     */      
    public HSSFCellStyle getColumnTopStyle(HSSFWorkbook workbook) {  
          // 设置字体  
          HSSFFont font = workbook.createFont();  
          //设置字体大小  
          font.setFontHeightInPoints((short)11);  
          //字体加粗  
          font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);  
          //设置字体名字   
          font.setFontName("Courier New");  
          //设置样式;   
          HSSFCellStyle style = workbook.createCellStyle();  
          //设置底边框;   
          style.setBorderBottom(HSSFCellStyle.BORDER_THIN);  
          //设置底边框颜色;    
          style.setBottomBorderColor(HSSFColor.BLACK.index);  
          //设置左边框;     
          style.setBorderLeft(HSSFCellStyle.BORDER_THIN);  
          //设置左边框颜色;   
          style.setLeftBorderColor(HSSFColor.BLACK.index);  
          //设置右边框;   
          style.setBorderRight(HSSFCellStyle.BORDER_THIN);  
          //设置右边框颜色;   
          style.setRightBorderColor(HSSFColor.BLACK.index);  
          //设置顶边框;   
          style.setBorderTop(HSSFCellStyle.BORDER_THIN);  
          //设置顶边框颜色;    
          style.setTopBorderColor(HSSFColor.BLACK.index);  
          //在样式用应用设置的字体;    
          style.setFont(font);  
          //设置自动换行;   
          style.setWrapText(false);  
          //设置水平对齐的样式为居中对齐;    
          style.setAlignment(HSSFCellStyle.ALIGN_CENTER);  
          //设置垂直对齐的样式为居中对齐;   
          style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);  
          return style;  
    }  
      
    /*   
     * 列数据信息单元格样式 
     */    
    public HSSFCellStyle getStyle(HSSFWorkbook workbook) {  
          // 设置字体  
          HSSFFont font = workbook.createFont();  
          //设置字体大小  
          //font.setFontHeightInPoints((short)10);  
          //字体加粗  
          //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);  
          //设置字体名字   
          font.setFontName("Courier New");  
          //设置样式;   
          HSSFCellStyle style = workbook.createCellStyle();  
          //设置底边框;   
          style.setBorderBottom(HSSFCellStyle.BORDER_THIN);  
          //设置底边框颜色;    
          style.setBottomBorderColor(HSSFColor.BLACK.index);  
          //设置左边框;     
          style.setBorderLeft(HSSFCellStyle.BORDER_THIN);  
          //设置左边框颜色;   
          style.setLeftBorderColor(HSSFColor.BLACK.index);  
          //设置右边框;   
          style.setBorderRight(HSSFCellStyle.BORDER_THIN);  
          //设置右边框颜色;   
          style.setRightBorderColor(HSSFColor.BLACK.index);  
          //设置顶边框;   
          style.setBorderTop(HSSFCellStyle.BORDER_THIN);  
          //设置顶边框颜色;    
          style.setTopBorderColor(HSSFColor.BLACK.index);  
          //在样式用应用设置的字体;    
          style.setFont(font);  
          //设置自动换行;   
          style.setWrapText(false);  
          //设置水平对齐的样式为居中对齐;    
          style.setAlignment(HSSFCellStyle.ALIGN_CENTER);  
          //设置垂直对齐的样式为居中对齐;   
          style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);  
          return style;  
    }  

    /**
     * 将workbook保存为文件
     *
     * @param wb
     * @param filePath
     */
    public void saveWorkBook(HSSFWorkbook wb, String filePath) {
        try {
            FileOutputStream fileOut = new FileOutputStream(filePath);
            wb.write(fileOut);
            fileOut.close();
        } catch (FileNotFoundException ex) {
            System.out.println(ex.getMessage());
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }
    }

    /**
     * 创建个workbool
     *
     * @return
     */
    public HSSFWorkbook createWorkbook() {
        HSSFWorkbook wb = new HSSFWorkbook();
        return wb;
    }

    /**
     * 创建个sheet
     *
     * @param wb
     * @return
     */
    public HSSFSheet createSheet(HSSFWorkbook wb) {
        return wb.createSheet();
    }

    /**
     * 创建个sheet
     *
     * @param wb        workbook对象
     * @param sheetname sheet的名称
     * @return
     */
    public HSSFSheet createSheet(HSSFWorkbook wb, String sheetname) {
        return wb.createSheet(sheetname);
    }

    /**
     * 创建新行
     *
     * @param sheet  sheet对象
     * @param rownum 行序号
     * @return
     */
    public HSSFRow createRow(HSSFSheet sheet, int rownum) {
        return sheet.createRow(rownum);
    }


    /**
     * 创建Cell
     *
     * @param row    行对象
     * @param colnum 列序号
     * @return
     */
    public HSSFCell createCell(HSSFRow row, int colnum) {
        return row.createCell(colnum);
    }

    /**
     * 设置cell的值
     *
     * @param cell
     * @param value
     */
    public void setCellValue(HSSFCell cell, String value) {
        cell.setCellValue(value);
    }

    /**
     * 合并单元格，合并后值位左上角的值
     * @param sheet
     * @param firstrow
     * @param lastrow
     * @param firstcol
     * @param lastcol
     */
    public void mergeRegion(HSSFSheet sheet,int firstrow,int lastrow,int firstcol,int lastcol){
        sheet.addMergedRegion(new CellRangeAddress(firstrow,lastrow,firstcol,lastcol));
    }

    /**
     * 获得cell的样式  自动换行
     *
     * @param wb
     * @param bold 是否加粗
     * @return
     */
    public HSSFCellStyle getCellStyle(HSSFWorkbook wb, boolean bold) {

        HSSFCellStyle style = wb.createCellStyle();
        // 创建字体样式
        HSSFFont font = wb.createFont();
        font.setFontName("Calibri");
        if (bold) {
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font.setFontHeightInPoints((short)11);
            
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平
        }
        //HSSFDataFormat format= wb.createDataFormat();
        //style.setDataFormat(format.getFormat("_(*#,##0.00_);_(*(#,##0.00);_(*\\\"-\\\"??_);_(@_)"));
        //style.setWrapText(true);// 自动换行
        style.setFont(font);
        return style;
    }
    
    //获得字体颜色样式
    public HSSFCellStyle getFontStyle(HSSFWorkbook wb,short colorindex,boolean blod) {
    	HSSFCellStyle style = wb.createCellStyle();
    	HSSFFont font = wb.createFont();
    	font.setColor(colorindex);    //设置字体颜色
    	font.setFontName("Calibri");//字體樣式
    	if (blod){
    	    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    	}
    	font.setFontHeightInPoints((short) 11);// 设置字体大小
    	style.setFont(font);
    	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中 
    	style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//垂直居中  
    	style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    	style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    	style.setBorderRight(HSSFCellStyle.BORDER_THIN);
    	style.setBorderTop(HSSFCellStyle.BORDER_THIN);
    	return style;
	}
    //获得填充颜色样式
    public HSSFCellStyle getFillStyle(HSSFWorkbook wb,short colorindex) {
    	HSSFCellStyle style = wb.createCellStyle();
    	HSSFFont font = wb.createFont();
    	font.setFontName("Calibri");//字體樣式
    	font.setFontHeightInPoints((short) 11);// 设置字体大小
    	style.setFont(font);
    	style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中 
    	style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//垂直居中  
    	style.setFillForegroundColor(colorindex);    //填充颜色
    	style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    	style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    	style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    	style.setBorderRight(HSSFCellStyle.BORDER_THIN);
    	style.setBorderTop(HSSFCellStyle.BORDER_THIN);
    	return style;
	}
    
    //设置颜色，默认的到56，不能操作64个
    public void setColorIndex(HSSFWorkbook wb,short index,byte r,byte g,byte b){
    	HSSFPalette hp=wb.getCustomPalette();
    	hp.setColorAtIndex(index,r,g,b);
    }
    
    public HSSFCellStyle getBorderStyle(HSSFWorkbook wb){
    	HSSFCellStyle style = wb.createCellStyle();
    	style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    	style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    	style.setBorderRight(HSSFCellStyle.BORDER_THIN);
    	style.setBorderTop(HSSFCellStyle.BORDER_THIN);
    	return style;
    }

    /**
     * 获取excel文件的workbook
     *
     * @param filePath 文件路径
     * @return
     */
    public HSSFWorkbook getWorkBook(String filePath) {
        try {
        	
        	
            FileInputStream fileIn = new FileInputStream(filePath);
            HSSFWorkbook wb = new HSSFWorkbook(fileIn);

            fileIn.close();
            return wb;
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return null;
        }

    }
    

    /**
     * 获取excel的sheet对象
     *
     * @param wb          workbook
     * @param sheetnumber sheet的序号
     * @return
     */
    public HSSFSheet getSheet(HSSFWorkbook wb, int sheetnumber) {
        HSSFSheet sheet = wb.getSheetAt(sheetnumber);
        return sheet;
    }

    /**
     * 获取excel的sheet对象
     *
     * @param wb        workbook
     * @param sheetname sheet的名称
     * @return
     */
    public HSSFSheet getSheet(HSSFWorkbook wb, String sheetname) {
        HSSFSheet sheet = wb.getSheet(sheetname);
        return sheet;
    }

    /**
     * @param sheet
     * @param rowIndex
     * @param columnIndex
     * @return
     */

    public HSSFCell getCell(HSSFSheet sheet, int rowIndex, short columnIndex) {
        HSSFRow row = sheet.getRow(rowIndex);
        if (row == null) {
            return null;
        }

        HSSFCell cell = row.getCell(columnIndex);
        return cell;
    }

    /**
     * 根据cell的类型读取cell的值
     *
     * @param cell
     * @return
     */
    public String getCellValue(HSSFCell cell) {
        if (cell == null) {
            return null;
        }
        String value = "";
        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC: // 数值型
                if (DateUtil.isCellDateFormatted(cell)) {
                    // 如果是date类型则 ，获取该cell的date值
                    // 修改DateFormat为yyyy/MM/dd
                    // 周伟
                    // 2013/5/20
                    SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd");
                    value = dateformat.format(DateUtil.getJavaDate(cell.getNumericCellValue()));
                    //value = DateFormat.getDateInstance().format(DateUtil.getJavaDate(cell.getNumericCellValue()));
                } else {// 纯数字
                    double dvalue = cell.getNumericCellValue();
                    value = String.valueOf(cell.getNumericCellValue());
                    if (dvalue > 1) {
                        if (value.contains(".")) {
                            int index = value.indexOf(".");
                            if (index < value.length() - 2) {
                                value = String.format("%.0f", dvalue);
                            } else {
                                value = value.substring(0, index);
                            }
                        }
                    }
                }
                break;
                 /* 此行表示单元格的内容为string类型 */
            case Cell.CELL_TYPE_STRING: // 字符串型
                value = cell.getRichStringCellValue().toString();
                break;
            case Cell.CELL_TYPE_FORMULA:// 公式型
                // 读公式计算值
                value = String.valueOf(cell.getNumericCellValue());
                if (value.equals("NaN")) {// 如果获取的数据值为非法值,则转换为获取字符串
                    value = cell.getRichStringCellValue().toString();
                } else {
                    double d = Double.parseDouble(value);
                    if (d > 1) {
                        value = String.format("%.0f", d);
                    } else {
                        value = String.format("%.2f", d);
                    }
                }
                // cell.getCellFormula();读公式
                break;
            case Cell.CELL_TYPE_BOOLEAN:// 布尔
                value = " " + cell.getBooleanCellValue();
                break;
				 /* 此行表示该单元格值为空 */
            case Cell.CELL_TYPE_BLANK: // 空值
                value = "";
                break;
            case Cell.CELL_TYPE_ERROR: // 故障
                value = "";
                break;
            default:
                value = cell.getRichStringCellValue().toString();
        }
        return value.trim();
    }

    /**
     * 获得sheet下的固定行、固定列的值
     *
     * @param sheet
     * @param rowIndex
     * @param columnIndex
     * @return
     */
    public String getCellValue(HSSFSheet sheet, int rowIndex, short columnIndex) {
        HSSFCell cell = getCell(sheet, rowIndex, columnIndex);
        if (cell == null) {
            return null;
        }
        return getCellValue(cell);
    }
    
    /**
     * 获得sheet下的固定行、固定列的值
     *
     * @param sheet
     * @param rowIndex
     * @param columnIndex
     * @return
     */
    public void setCellValue(HSSFRow row, short columnIndex,String value) {
        HSSFCell cell = row.getCell(columnIndex);
        if (cell == null) {
        	 cell = createCell(row, columnIndex);
        }
        setCellValue(cell, value);
    }
    
    public HSSFRow getRow(HSSFSheet sheet,int rowIndex) {
    	 HSSFRow row = sheet.getRow(rowIndex);
    	 return row;
	}
    
    /**
     * 获得sheet下的固定行、固定列的值
     *
     * @param sheet
     * @param rowIndex
     * @param columnIndex
     * @return
     */
    public void setCellValue(HSSFSheet sheet, int rowIndex, short columnIndex,String value) {
        HSSFCell cell = getCell(sheet, rowIndex, columnIndex);
        if (cell == null) {
            return ;
        }
        setCellValue(cell, value);
    }

    /**
     * 获取sheets的个数
     *
     * @param wb
     * @return
     */
    public int getSheetCount(HSSFWorkbook wb) {
        return wb.getNumberOfSheets();
    }

    /**
     * 获得sheet总行数
     *
     * @param sheet
     * @return
     */
    public int getRowCount(HSSFSheet sheet) {
        return sheet.getLastRowNum();
    }

    /**
     * 获得sheet的列数
     *
     * @param sheet
     * @return
     */
    public int getColumnCount(HSSFSheet sheet) {
        return sheet.getRow(0).getPhysicalNumberOfCells();
    }
}
